<?php
@$ddid= $_REQUEST["ddid"];
$y= "未结账";
@$czid= $_REQUEST["czid"];

$pdo = new PDO("mysql:dbname=caipin;host=127.0.0.1;charset=UTF8", "root", "root");
$sql = $pdo->prepare("select * from zhuohao left join zhuocai on zhuohao.zhuoid=zhuocai.zhuoId left join useraa on zhuocai.caiId=useraa.id where zhuohao.zhuoid=:id;");
$sql->execute(array("id"=>$ddid));
$arr = $sql->fetchAll(PDO::FETCH_NAMED);

$uu=0;
if(isset($arr)){
    for($e=0;$e < count($arr); $e++) {
        $w = $arr[$e];
        $uu += floatval($w["jiage"]);
    }
}
$sql9 = $pdo->prepare("insert into dindan(zhuoId,caiId ,shijian,zongjia,jz)values(:n,:p,now(),:j,:i);");
$sql9->execute(array("n" => $czid,"p" => $ddid, "j" => $uu,"i" => $y));

header('Location:dindanliebiao.php');
